web/src/pages/inventory/[...inventoryId].astro

101 lines · 2416 bytes

  1---
  2import Layout from '@layouts/Layout.astro';
  3import SavedServices from '@components/things/SavedServices.svelte';
  4
  5import Button from '@components/form/Button.astro';
  6
  7export const prerender = false;
  8
  9const inventoryId = Astro.params.inventoryId || 'Inventory';
 10let cheekyLilError = '';
 11
 12function makeTitle(input: string): string {
 13	return (input.includes('_') ? input : `mystry_${input}`)
 14		.split('_')[1]
 15		.replace(/-/g, ' ')
 16		.replace(/\b\w/g, (match) => match.toUpperCase());
 17}
 18
 19const serviceList =
 20	(await fetch(
 21		`https://awesome-privacy-share-api.as93.net/${inventoryId}`,
 22	).then((res) => res.json())) || [];
 23
 24if (serviceList.error) {
 25	cheekyLilError = serviceList.error;
 26}
 27---
 28
 29<Layout title={`${makeTitle(inventoryId)} | Awesome Privacy`}>
 30	<main>
 31		<h1>{makeTitle(inventoryId)}</h1>
 32		{
 33			cheekyLilError && (
 34				<div class="error">
 35					<p class="oh-deary-me">An error occoured</p>
 36					<p class="what-the-fuck-happened">{cheekyLilError}</p>
 37					<p class="what-next">
 38						We're sorry about that.
 39						<br />
 40						Try going <a href="/">back home</a>, or{' '}
 41						<a href="https://github.com/Lissy93/awesome-privacy/issues/new/choose">
 42							raising a ticket
 43						</a>{' '}
 44						on GitHub.
 45					</p>
 46				</div>
 47			)
 48		}
 49		<SavedServices serviceList={serviceList} client:load />
 50		<div class="buttons">
 51			<p>Not found what you're looking for?</p>
 52			<Button url="/all/">Browse Services</Button>
 53		</div>
 54	</main>
 55</Layout>
 56
 57<style lang="scss">
 58	main {
 59		margin: 0 auto var(--space-lg) auto;
 60		padding: var(--space-md);
 61		width: var(--width-container);
 62		max-width: var(--width-container-max);
 63		display: flex;
 64		justify-content: space-between;
 65		flex-direction: column;
 66		min-height: calc(100vh - 12rem);
 67		font-size: var(--text-md);
 68		h1 {
 69			font-family: var(--font-subtitle);
 70			font-weight: bold;
 71			font-size: var(--text-4xl);
 72			margin: 0;
 73			color: var(--accent-3-text);
 74		}
 75		.buttons {
 76			margin: var(--space-md) auto;
 77			display: flex;
 78			flex-direction: column;
 79		}
 80		.error {
 81			text-align: center;
 82			font-size: var(--text-lg);
 83			.oh-deary-me {
 84				font-size: var(--text-2xl);
 85				margin: 0.2rem auto;
 86			}
 87			.what-the-fuck-happened {
 88				color: var(--danger);
 89				margin: 0.2rem auto;
 90			}
 91			.what-next {
 92				font-size: var(--text-base);
 93				margin-top: var(--space-xl);
 94				opacity: var(--opacity-muted);
 95				a {
 96					color: var(--foreground);
 97				}
 98			}
 99		}
100	}
101</style>